<template>
	<view class="increase_height">
		<view v-if="type == 'add'">
			<view class="data" @click="addData">
				<text>日期</text>
				<text>{{wight_time}}</text>
				<image class="data_img" :src="require('../../status/image/arr.png')" mode=""></image>
			</view>
			<view class="height">
				<text>身高(cm)</text>
				<input type="number" maxlength="5" placeholder="请输入身高" v-model="height">
			</view>
			<view class="width">
				<text>体重(kg)</text>
				<input type="number" maxlength="5" placeholder="请输入体重" v-model="width">
			</view>
			
			<view class="btn_increase" @click="addHeight">保存</view>
			<!-- 日期选择 -->
			<u-picker mode="time" v-model="showTime" @confirm='confirmTime'></u-picker>
		</view>
		
		<view v-else class="info_list">
			<view class="info_item"> 
				<text>日期</text>
				<text>{{heightWightList.wight_time}}</text>
			</view>
			
			<view class="info_item">
				<text>身高(cm)</text>
				<text>{{heightWightList.height}}</text>
			</view>
			
			<view class="info_item">
				<text>体重(kg)</text>
				<text>{{heightWightList.wight}}</text>
			</view>
			
			<view class="info_item">
				<text>BMI</text>
				<text>{{heightWightList.BMI}}</text>
			</view>
			
			<view class="info_item_deta">
				<text>BMI即身体质量指数, 是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。</text> 
				<text>过轻: BMI {{dialogback}} 18.5 </text>  
				<text>正常：18.5{{beEqualTo}}BMI{{dialogback}}25</text>
				<text>过重： 25{{beEqualTo}}BMI{{dialogback}}30</text>
				 <text>肥胖：30{{beEqualTo}}BMI{{dialogback}}35</text>
				 <text>非常肥胖：BMI{{daEqualTo}}35</text>
				  
			</view>
			
			<!-- 底部 -->
			<view class="info_foo_btn">
				<text style="margin-right: 10rpx;" @click="deleteInfo">删除</text>
				<text style="margin-left: 10rpx; background-color: #00c077; color: #fff;">保存</text>
			</view>
		</view>
		<!-- 消息提示 -->
		<u-top-tips ref="uTips"></u-top-tips>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				dialogback:'<',
				 beEqualTo: '≤',
				  daEqualTo: '≥',
				showTime: false,
				wight_time: '选择测量时间',
				height: '',
				width: '',
				returnPageTime: null,
				// 页面类型
				type: 'add',
				// 返回上一页
				goToPreviousTime: null, 
				heightWightList: {}
			};
		},
		onLoad(options) { 
			this.type = options.type
		},
		onShow() {
			this.getHeightWight()
		},
		onHide() {
			clearTimeout(this.returnPageTime)
			clearTimeout(this.goToPreviousTime)
		},
		methods: {
			addData() {
				this.showTime = true
			},
			confirmTime(val) {
				this.wight_time = val.year + '-' + val.month + '-' + val.day
			},
			// 添加体重身高
			addHeight() {

				if (this.wight_time == '选择测量时间') {
					this.$refs.uTips.show({
						title: '选择测量时间',
						type: 'warning', 
						duration: '1500'
					})
					return false
				}else if (this.height == ''){
					this.$refs.uTips.show({
						title: '请填写身高',
						type: 'warning',
						duration: '1500'
					})
					return false
				}else if (this.width == ''){
					this.$refs.uTips.show({
						title: '请填写体重',
						type: 'warning',
						duration: '1500'
					})
					return false
				}

				this.$api.sendRequest({
					url: 'api/health/addHeight',
					data: {
						wight_time: this.wight_time,
						height: this.height,
						wight: this.width
					},
					success: res => {
						if(res.code >= 0){
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
						clearTimeout(this.returnPageTime)
						this.returnPageTime = setTimeout(() => {
								uni.reLaunch({
									url: '../addarcguves/index'
								})
							},1000)
						} 
					}
				})
			},
			// 查询身高
			getHeightWight() {
				this.$api.sendRequest({
					url: '/api/health/heightWight',
					success: res => {
						if (res.code >= 0) { 
							this.heightWightList = res.data
							console.log(this.heightWightList)
						}
					}
				})
			},
			// 删除数据
			deleteInfo(){
				let _this = this
				_this.$api.sendRequest({
					url: '/api/health/delHeight',
					success: res => {
						if(res.code >= 0){ 
							uni.showToast({
								title: '删除成功',
								icon: 'none'
							})
							clearTimeout(_this.goToPreviousTime) 
							_this.goToPreviousTime = setTimeout(() => {
								uni.navigateBack()
							},1000)
						}
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.increase_height {
		height: 100%;

		.data,
		.height,
		.width {
			display: flex;
			justify-content: space-between;
			padding: 0 20rpx;
			height: 80rpx;
			line-height: 80rpx;
			background-color: #fff;
			border-bottom: 2rpx solod #eee;

			input {
				height: 100%;
				width: 200rpx;
			}
		}

		.data {
			position: relative;
			padding-right: 80rpx;

			.data_img {
				position: absolute;
				top: 50%;
				right: 10rpx;
				transform: translate(0, -50%);
				width: 35rpx;
				height: 35rpx;
			}
		}

		.btn_increase {
			margin: 60rpx;
			height: 60rpx;
			line-height: 60rpx;
			text-align: center;
			color: #fff;
			border-radius: 20rpx;
			background-color: #00b26a;
		}
		
		.info_list{
			.info_item{
				display: flex;
				justify-content: space-between;
				padding: 0 20rpx;
				height: 80rpx;
				line-height: 80rpx;
				background-color: #fff;
				border-bottom: 2rpx solid #eee;
			}
			.info_item_deta{
				padding: 40rpx 20rpx;
				color: #827b75;
				text {
					display: block;
				}
			}
			.info_foo_btn{
				display: flex;
				padding: 20rpx 30rpx 0 30rpx;
				justify-content: space-around;
				position: fixed;
				bottom: 0;
				width: 100%;
				height: 140rpx; 
				text-align: center;
				background-color: #fff;
				text {
					height: 80rpx;
					line-height: 80rpx;
					flex: 1;
					color: #01c178;
					border: 2rpx solid #01c178;
					border-radius: 20rpx;
				}
			}
		}
	
	
	}
</style>
